package org.niugang.security.users.pojo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @author Created by niugang on 2018/12/26/13:40
 */
@Data
@ToString
@EqualsAndHashCode
public class UserDO implements UserDetails {
	private Integer id;
	private String account;
	private String name;
	private String sex;
	private String phone;
	private String email;
	private String quanPin;
	private String jianPin;
	private String ip;
	private Integer deptId;
	private String idCard;
	private String fileUrl;
	private String password;
	private String deleteFlag;
	private Date createTime;
	private String creator;
	private Date updateTime;
	private String updator;
	private Long version;

   private List<RoleDO> authorities;

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
//	    List<GrantedAuthority> objects = new ArrayList(){
//			{
//				//对应controller中的  @PreAuthorize("hasAuthority('admin')")
//              add( new SimpleGrantedAuthority("admin"));
//			}
//		};
//		return objects;
		return authorities;
	}

	public void setAuthorities(List<RoleDO> authorities) {
		this.authorities = authorities;
	}

	@Override
	public String getUsername() {
		return account;
	}

	@Override
	public boolean isAccountNonExpired() {
		return false;
	}

	@Override
	public boolean isAccountNonLocked() {
		return false;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return false;
	}

	@Override
	public boolean isEnabled() {
		return false;
	}
}
